package com.learn.blog.admin.controller;

import com.learn.blog.admin.model.params.PageParam;
import com.learn.blog.admin.pojo.Admin;
import com.learn.blog.admin.pojo.Permission;
import com.learn.blog.admin.service.AdminService;
import com.learn.blog.admin.service.PermissionService;
import com.learn.blog.admin.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Package: com.learn.blog.admin.controller
 * @ClassName: AdminController
 * @Author: 陈威
 * @CreateTime: 2021/9/14 17:19
 * @Description:
 */
@RestController
@RequestMapping("admin")
public class AdminAndPermissionController {

    @Autowired
    PermissionService permissionService;
    @Autowired
    AdminService adminService;

    @PostMapping("permission/permissionList")
    public Result listPermission(@RequestBody PageParam pageParam) {
        return permissionService.listPermission(pageParam);

    }

    @PostMapping("permission/add")
    public Result add(@RequestBody Permission permission) {
        return permissionService.add(permission);
    }

    @PostMapping("permission/update")
    public Result update(@RequestBody Permission permission) {
        return permissionService.update(permission);
    }

    @GetMapping("permission/delete/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return permissionService.delete(id);
    }

    //---------------------------------------以下是跟用户有关的api----------------------------------------------


    @PostMapping("user/userList")
    public Result userList(@RequestBody PageParam pageParam) {
        return adminService.userList(pageParam);
    }


    @PostMapping("user/addUser")
    public Result addUser(@RequestBody Admin admin) {
        return permissionService.addUser(admin);
    }

    @PostMapping("user/updateUser")
    public Result updateUser(@RequestBody Admin admin) {
        return permissionService.updateUser(admin);
    }

    @GetMapping("user/deleteUser/{id}")
    public Result deleteUser(@PathVariable("id") Long id) {
        return permissionService.deleteUser(id);
    }
}